package com.atguigu.source;

import org.apache.flink.api.connector.source.Source;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Arrays;
import java.util.List;

/**
 * @author yhm
 * @create 2024-04-01 14:42
 */
public class Test01_Collection {
    public static void main(String[] args) throws Exception {
        // 1. 创建环境
        Configuration conf = new Configuration();
        conf.setInteger("rest.port",8081);

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);

        env.setParallelism(1);

        // 2. 读取数据源
        // 1.12版本之前
        // 参数填写是SourceFunction 相对比较老  没有很好的兼容各种不同的框架
        env.addSource(new SourceFunction<Object>() {
            @Override
            public void run(SourceContext<Object> ctx) throws Exception {

            }

            @Override
            public void cancel() {

            }
        });

        // 1.12版本之后
        // 参数填写是Source 标准化的接口连接器   需要读取哪种数据源就添加哪种source
//        env.fromSource(Source)

        List<String> strings = Arrays.asList("hello", "atguigu", "hi");
        DataStreamSource<String> stringDataStreamSource = env.fromCollection(strings);

        // 3. 处理数据

        // 4. 输出
        stringDataStreamSource.print();

        // 5. 执行环境
        env.execute();

    }
}
